﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace NAutoForm.utils
{
    public class UsernameUtils
    {

        /// <summary>
        /// 生成用户名
        /// </summary>
        /// <param name="length"></param>
        /// <returns></returns>
        public static string GetUsername()
        {
            Random rd = new Random();
            int length = rd.Next(5, 12);
            byte[] str = new byte[length];
            int i;
            for (i = 0; i < length - 1; i++)
            {
                int a = 0;
                while (!((a >= 48 && a <= 57) || (a >= 97 && a <= 122)))
                {
                    a = rd.Next(48, 122);
                }
                str[i] = (byte)a;
            }
            string username = new string(UnicodeEncoding.ASCII.GetChars(str));
            Random r = new Random(unchecked((int)DateTime.Now.Ticks));
            string s1 = ((char)r.Next(97, 122)).ToString();
            username = username.Replace("/0", "");
            username = username.Replace("\0", "");
            username = username.Replace("\r\n", "");
            username = username.Replace("\t", "");
            username = username.Replace(" ", "");
            return $"{s1}{username}";
        }

        
    }
}
